package com.iflytek.universitymanagement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytek.universitymanagement.domain.SurveyQuestion;
import com.iflytek.universitymanagement.mapper.SurveyQuestionMapper;
import com.iflytek.universitymanagement.service.SurveyQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SurveyQuestionServiceImpl extends ServiceImpl<SurveyQuestionMapper, SurveyQuestion> implements SurveyQuestionService {

    private final SurveyQuestionMapper surveyQuestionMapper ;

    @Autowired
    public SurveyQuestionServiceImpl(SurveyQuestionMapper surveyQuestionMapper) {
        this.surveyQuestionMapper = surveyQuestionMapper;
    }

    @Override
    public List<SurveyQuestion> getAllQuestions() {
        return null;
    }

    @Override
    public void add(SurveyQuestion surveyQuestion) {
        surveyQuestionMapper.insertSurveyQuestion(surveyQuestion);
    }

//    @Override
//    public int calculateTotalScore(List<SurveyQuestionController.AnswerRequest> answers) {
//        return 0;
//    }


//    /**
//     * 计算总分
//     *
//     * @param answers 用户提交的答案列表
//     * @return 总分
//     */
//    @Override
//    public int calculateTotalScore(List<SurveyQuestionController.AnswerRequest> answers) {
//        int totalScore = 0;
//
//        // 遍历每个用户的答案，计算总分
//        for (SurveyQuestionController.AnswerRequest answer : answers) {
//            SurveyQuestion question = SurveyQuestionMapper.selectByTid(answer.getTid());
//            if (question != null) {
//                // 假设 tAnswer 存储的是正确答案的ID，用户选择的答案与正确答案对比
//                if (question.getAnswer().equals(answer.getSelectedAnswer())) {
//                    totalScore += question.getScore();  // 正确时加上题目的分数
//                }
//            }
//        }
//        return totalScore;
//    }

}